package com.ruoyi.methods.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.methods.domain.PaymentMethods;
import com.ruoyi.methods.service.IPaymentMethodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 支付方式管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/methods/methods")
public class PaymentMethodsController extends BaseController
{
    @Autowired
    private IPaymentMethodsService paymentMethodsService;

    /**
     * 查询支付方式管理列表
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaymentMethods paymentMethods)
    {
        startPage();
        List<PaymentMethods> list = paymentMethodsService.selectPaymentMethodsList(paymentMethods);
        return getDataTable(list);
    }

    /**
     * 导出支付方式管理列表
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:export')")
    @Log(title = "支付方式管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaymentMethods paymentMethods)
    {
        List<PaymentMethods> list = paymentMethodsService.selectPaymentMethodsList(paymentMethods);
        ExcelUtil<PaymentMethods> util = new ExcelUtil<PaymentMethods>(PaymentMethods.class);
        util.exportExcel(response, list, "支付方式管理数据");
    }

    /**
     * 获取支付方式管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:query')")
    @GetMapping(value = "/{paymentMethodId}")
    public AjaxResult getInfo(@PathVariable("paymentMethodId") Long paymentMethodId)
    {
        return success(paymentMethodsService.selectPaymentMethodsByPaymentMethodId(paymentMethodId));
    }

    /**
     * 新增支付方式管理
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:add')")
    @Log(title = "支付方式管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentMethods paymentMethods)
    {
        return toAjax(paymentMethodsService.insertPaymentMethods(paymentMethods));
    }

    /**
     * 修改支付方式管理
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:edit')")
    @Log(title = "支付方式管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentMethods paymentMethods)
    {
        return toAjax(paymentMethodsService.updatePaymentMethods(paymentMethods));
    }

    /**
     * 删除支付方式管理
     */
    @PreAuthorize("@ss.hasPermi('methods:methods:remove')")
    @Log(title = "支付方式管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentMethodIds}")
    public AjaxResult remove(@PathVariable Long[] paymentMethodIds)
    {
        return toAjax(paymentMethodsService.deletePaymentMethodsByPaymentMethodIds(paymentMethodIds));
    }
}
